﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace computerbookwebsite
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //1.创建连接对象
            SqlConnection cn = new SqlConnection();
            cn.ConnectionString =ConfigurationManager.ConnectionStrings["bookstoreConnectionString"].ConnectionString;
            cn.Open();

            //2.创建命令对象
            SqlCommand cm = new SqlCommand();
            cm.Connection = cn;
            cm.CommandText = string.Format("select*from member where LoginName='{0}' and LoginPwd='{1}'", txtUserName.Text, txtPassword.Text);

            //3.执行命令对象，返回数据阅读器
            SqlDataReader dr = cm.ExecuteReader();
            if (dr.Read())
            {
                String username = dr["LoginName"].ToString();
                Response.Write("<script>alert('" + username + "用户登录成功!')</script>");
            }

            //4.返回结果
            else
            {
                Response.Write("<script>alert( '用户名或密码不正确')</script>");
            }
            dr.Close();
            cn.Close();
        }
    }
}